package com.zmovie.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmovie.framework.domain.Cinema;
import com.zmovie.framework.service.CinemaService;
import com.zmovie.framework.mapper.CinemaMapper;
import org.springframework.stereotype.Service;

/**
* @author lenovo
* @description 针对表【cinema】的数据库操作Service实现
* @createDate 2023-11-27 19:49:32
*/
@Service
public class CinemaServiceImpl extends ServiceImpl<CinemaMapper, Cinema>
    implements CinemaService{

    @Override
    public Page<Cinema> pageCinema(Cinema cinema, Integer pageNo, Integer pageSize) {
        Page<Cinema> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Cinema> wrapper = new LambdaQueryWrapper<>();
        //条件查询：品牌、区域、是否支持改签、是否支持退票、影院名称、影院地址
        wrapper.eq(cinema.getBrandId() != null, Cinema::getBrandId, cinema.getBrandId());
        wrapper.eq(cinema.getAreaId() != null, Cinema::getAreaId, cinema.getAreaId());
        wrapper.eq(cinema.getIsTicketChanged() != null, Cinema::getIsTicketChanged, cinema.getIsTicketChanged());
        wrapper.eq(cinema.getIsRefunded() != null, Cinema::getIsRefunded, cinema.getIsRefunded());
        wrapper.like(cinema.getName() != null, Cinema::getName, cinema.getName());
        wrapper.like(cinema.getAddress() != null, Cinema::getAddress, cinema.getAddress());
        return page(page, wrapper);
    }

    @Override
    public boolean updateByIdCondition(Cinema cinema) {
        if(cinema.getId() == null){
            return false;
        }
        LambdaUpdateWrapper<Cinema> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Cinema::getId, cinema.getId());
        //是否可退款
        wrapper.set(cinema.getIsRefunded() != null, Cinema::getIsRefunded, cinema.getIsRefunded());
        //是否可改签
        wrapper.set(cinema.getIsTicketChanged() != null, Cinema::getIsTicketChanged, cinema.getIsTicketChanged());
        return update(wrapper);
    }
}




